package com.lp.biz.order.controller;

import com.lp.biz.order.model.query.OrderListQuery;
import com.lp.biz.order.model.vo.OrderRefund;
import com.lp.biz.order.service.BizOrderService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

import static com.lp.common.constant.MenuConstant.ORDER_LIST;

/**
 * BizOrderController
 * @program: backend
 * @author Ke.Song
 * @since 2024-05-26 11:00:59
 */
@RestController
@RequestMapping("/orders")
public class BizOrderController {

    @Autowired
    private BizOrderService orderService;

    /**
     * 退款
     * @param orderId 订单id
     * @return 处理结果
     */
    @PostMapping("/{orderId}/refund")
    @PermissionAnnotation(menus = {ORDER_LIST})
    public CommonResult orderRefund(@PathVariable Integer orderId, @RequestBody @Validated OrderRefund params) {
        orderService.orderRefund(orderId, params);
        return CommonResult.success();
    }

    /**
     * 获取订单列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping()
    @PermissionAnnotation(menus = {ORDER_LIST})
    public CommonResult orderList(OrderListQuery query) {
        return orderService.orderList(query);
    }

    /**
     * 获取订单详情
     * @param orderId 订单id
     * @return 查询结果
     */
    @GetMapping("/{orderId}")
    @PermissionAnnotation(menus = {ORDER_LIST})
    public CommonResult getOrderDetail(@PathVariable Integer orderId) {
        return orderService.getOrderDetail(orderId);
    }

    /**
     * 导出订单Excel
     * @param query 查询条件
     * @param response 响应体
     */
    @GetMapping("/export")
    @PermissionAnnotation(menus = {ORDER_LIST})
    public void exportOrders(OrderListQuery query, HttpServletResponse response) {
        orderService.exportOrders(query, response);
    }

}
